package com.aliyun.oss.service.impl;

import com.aliyun.oss.mapper.UserMapper;
import com.aliyun.oss.pojo.DTO.ShowUserInfoDTO;
import com.aliyun.oss.pojo.Entity.User;
import com.aliyun.oss.service.UserService;
import com.aliyun.oss.utils.GetNowTime;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>  implements UserService {
    @Override
    public List<User> getAllUsers() {
//        使用mybasticplus查询所有用户
        return list();
    }

    @Override
    public List<User> queryUserLikeByName(String name) {

//        根据员工名模糊查询员工
        return list(new QueryWrapper<User>().like("name",name));
    }

    @Override
    public void updateUserById(Integer operatorId, ShowUserInfoDTO showUserInfoDTO) {
//        根据员工id修改特定员工信息
        LocalDateTime nowTime = GetNowTime.getNowTime();
        update(new User(showUserInfoDTO.getName(),showUserInfoDTO.getUsername(),showUserInfoDTO.getPassword(),showUserInfoDTO.getPhone(),showUserInfoDTO.getSex(),nowTime,operatorId),new QueryWrapper<User>().eq("id",showUserInfoDTO.getId()));
    }

    @Override
    public void updateUserStatusById(Integer operatorId, Integer id, Integer status) {
        LocalDateTime nowTime = GetNowTime.getNowTime();
//        根据员工id修改员工状态
        update(new User(operatorId,nowTime,status),new QueryWrapper<User>().eq("id", id));
    }

    @Override
    public void addUser(Integer operatorId, ShowUserInfoDTO showUserInfoDTO) {
        LocalDateTime nowTime = GetNowTime.getNowTime();
//        添加员工
        save(new User(showUserInfoDTO.getName(),showUserInfoDTO.getUsername(),showUserInfoDTO.getPassword(),showUserInfoDTO.getPhone(),showUserInfoDTO.getSex(),1,nowTime,nowTime,operatorId,operatorId));
    }

    @Override
    public void updateUserPasswordById(Integer operatorId, String password) {
        LocalDateTime nowTime = GetNowTime.getNowTime();
        update(new User(Long.valueOf(operatorId),password,nowTime),new QueryWrapper<User>().eq("id", operatorId));

    }
}
